const app = getApp();

const user = {
    /*
     * 获取用户信息
     */
    async getUserInfo(jwt) {
        let userInfo = await new Promise((resolve, reject) => {
            wx.request({
                url: `${app.globalData.server_addr}/users/getUserInfoByJwt`,
                method: 'POST',
                data: {
                    jwt: jwt
                },
                success: (res) => {
                    if (res.data.userInfo) {
                        console.log('获取用户信息成功');
                        resolve(res.data.userInfo);
                    } else {
                        console.log('获取用户信息失败');
                        resolve(res.data.userInfo);
                    }
                },
                fail: (err) => {
                    console.log('获取用户信息失败', err);
                    resolve(res.data.userInfo);
                }
            });
        });
        return userInfo;
    },
};

module.exports = user;